package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.AttributeNewDto;
import cn.tedu.csmall.product.pojo.dto.PictureAddNewDto;
import cn.tedu.csmall.product.service.PictureService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.*;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/picture")
@Api(tags = "图片管理模块")
public class PictureController {
    @Autowired
    PictureService service;

    /**
     * 添加属性
     *
     * @return
     */
    @PostMapping("/add-new")
    @ApiOperation("添加图片")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(PictureAddNewDto addNewDto) {
        service.addNew(addNewDto);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("根据ID删除图片")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "图片ID", required = true, dataType = "long"),
    })
    public JsonResult<Void> delete(@PathVariable @Range(min = 1) Long id) {
        service.delete(id);
        return JsonResult.ok();
    }
}
